using System.Runtime.Serialization;
using MiniStock.Entities.Common;

namespace MiniStock.Entities.Stock.Events.Customer
{
    [DataContract]
    public class ChangeCustomerNameEvent : CustomerEventBase
    {
        [DataMember]
        public string Name { get; set; }

        public override void ValidateFor(EntityBase entity, IEntityProvider provider)
        {
            base.ValidateFor(entity, provider);

            Stock.Customer.Validator.CustomerNameMandatory((Stock.Customer)entity, provider, Name);
            Stock.Customer.Validator.CustomerNameUnique((Stock.Customer)entity, provider, Name);
        }

        public override void ApplyTo(EntityBase entity)
        {
            ((Stock.Customer) entity).Name = Name;
        }
    }
}